<?php

function is_empty($value) {
    if ($value == "") {
        return true;
    }
    return false;
}
?>
<style>
    .left{
        text-align: left;
    }
</style>
<title>Notifications Tracking</title>
<h1>Notifications Tracking</h1>
<div id="view-content">    
    <div class="well">
        <table class="table table-condensed table-striped table-bordered">
            <thead>
                <tr>
                    <th class="span1">#</th>
                    <th>Name</th>
                    <th>Email</th>
                    <th>Email Events</th>
                    <th>Mobile Number</th>
                    <th>Date</th>
                </tr>
            </thead>
            <tbody>                
                <?php
                $index = 1;
                foreach ($this->fetchAll as $track) :
                    ?>
                    <tr>
                        <td><h1><?= $index ?></h1></td>
                        <td><?= $track['name'] ?></td>
                        <td><?= $track['email']->email ?></td>
                        <td>
                            <?php
                            $events = $track['email']->events;

                            if (!is_empty($events->delivered)) {
                                echo "<a class='btn btn-mini btn-success span2 left'><i class='icon-white icon-ok-sign'></i> &nbsp;&nbsp;&nbsp; Delivered</a><br>";
                            }
                            if (!is_empty($events->open)) {
                                echo "<a class='btn btn-mini btn-success span2 left'><i class='icon-white icon-ok-sign'></i> &nbsp;&nbsp;&nbsp; Opened</a><br>";
                            }
                            if (!is_empty($events->click)) {
                                echo "<a class='btn btn-mini btn-success span2 left'><i class='icon-white icon-ok-sign'></i> &nbsp;&nbsp;&nbsp; Clicked</a><br>";
                            }
                            if (!is_empty($events->bounce)) {
                                echo "<a class='btn btn-mini btn-info span2 left'><i class='icon-white icon-ok-sign'></i> &nbsp;&nbsp;&nbsp; Bounced</a><br>";
                            }
                            if (!is_empty($events->dropped)) {
                                echo "<a class='btn btn-mini btn-warning span2 left'><i class='icon-white icon-ok-sign'></i> &nbsp;&nbsp;&nbsp; Dropped</a><br>";
                            }
                            if (!is_empty($events->spamreport)) {
                                echo "<a class='btn btn-mini btn-danger span2 left'><i class='icon-white icon-ok-sign'></i> &nbsp;&nbsp;&nbsp; Marked As Spam</a><br>";
                            }
                            if (!is_empty($events->unsubscribe)) {
                                echo "<a class='btn btn-mini btn-inverse span2 left'><i class='icon-white icon-ok-sign'></i> &nbsp;&nbsp;&nbsp; Unsubscribed</a><br>";
                            }
                            ?>
                        </td>
                        <td><?= $track['sms']->mobile ?><br>
                            <?php
                            if ($track['sms']->mobile != null) {
                                if ($track['sms']->isVerified) {
                                    if ($track['sms']->sent) {
                                        echo "<span class='label label-success'>Sent</span>";
                                        //echo "<a class='btn btn-mini btn-success'><i class='icon-white icon-ok-sign'></i> Sent</a>";
                                    } else {
                                        echo "<a class='btn btn-mini btn-danger'><i class='icon-white icon-remove-sign'></i> Not Sent</a>";
                                    }
                                }else{
                                    echo "<span class='label label-warning'>Not Verified</span>";
                                   //echo "<a class='btn btn-mini btn-danger'><i class='icon-white icon-remove-sign'></i> Not Verified</a>";
                                }
                            }
                            ?>
                        </td>
                        <td><?= $track['date'] ?></td>            
                    </tr>
                    <?php
                    $index++;
                endforeach;
                ?>
            </tbody>
        </table>
    </div>

</div>